Page({
    data: {
      bookid: '',
      name: '',
      pic: '',
      price: '',
      author: '',
      zhurenPic: '',
      zhurenName: '',

      index: 0,

      params: {
        userIds: wx.getStorageSync('userId'),
        bookInfoId: '',
        content: ''
      }
    },


    getIndex (id) {
      var _this = this
      var params = {
        bookInfoId: id
      }
      wx.request({
        url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/afterReading/getIndex/auth',
        data: params,
        method: 'POST',
        header: {
          "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
          "token": wx.getStorageSync('token'),
          "uid": wx.getStorageSync('uuid')
        },
        success: (res) => {
          if (res.data.code == 200) {
            _this.setData({
              index: res.data.data
            })
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      })
    },

    //绑定content
    bindcontent (e) {
      console.log(e)
      var content = e.detail.value
      var contentValue = "params.content"
      this.setData({
        [contentValue]: content
      })
    },
    onLoad (options) {
      var bookinfo = "params.bookInfoId"
      this.setData({
        bookid: options.bookids,
        [bookinfo]: options.bookids,
        name: options.name,
        pic: options.pic,
        price: options.price,
        author: options.author,
        zhurenPic: wx.getStorageSync('avatarUrl'),
        zhurenName: wx.getStorageSync('nickName')
      })
      this.getIndex(this.data.bookid)
    },


    //提交
  getScancode () {
    if (this.data.params.content=='') {
      wx.showToast({
        title: '请编写您的读后感觉',
        icon: 'none'
      })
      return
    }
    this.addFeel(this.data.params)
  },

  addFeel (params) {
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/afterReading/mod/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {
          wx.showToast({
            title: '提交成功',
            icon: 'none',
            duration:2000
          })
          setTimeout(function () {
            wx.navigateBack()
          },2000)
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  }
})
